#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> ans;
        vector<int> dp1(n, 1), dp2(n, 1);
        for (int i = 1; i < n; i++)
            dp1[i] = dp1[i - 1] * nums[i - 1];
        for (int i = n - 2; i >= 0; i--)
            dp2[i] = dp2[i + 1] * nums[i + 1];
        for (int i = 0; i < n; i++)
            ans.push_back(dp1[i] * dp2[i]);
        return ans;
    }
};